package com.ls.pattern.state.v2;


public class OrderService {

    public static void main(String[] args) {
        OrderStateMachine stateMachine = new OrderStateMachine(OrderStateEnum.WAIT_DELIVER);

        invoke(stateMachine::pay, "用户支付", stateMachine);
        invoke(stateMachine::deliver, "商家发货", stateMachine);
        invoke(stateMachine::receive, "用户收货", stateMachine);
        invoke(stateMachine::cancel, "取消支付", stateMachine);
        invoke(stateMachine::refund, "申请退款", stateMachine);
        invoke(stateMachine::confirmRefund, "确认退款", stateMachine);
    }

    public static void invoke(Runnable runnable, String desc, OrderStateMachine stateMachine) {
        System.out.println(desc + "前订单状态: " + stateMachine.getCurrentState().orderStateType().getDesc());
        runnable.run();
        System.out.println(desc + "后订单状态: " + stateMachine.getCurrentState().orderStateType().getDesc());
        System.out.println("------------------");
    }

}
